import { WECHAT } from "cc/env";
import { ecs } from "../../../../../extensions/oops-plugin-framework/assets/libs/ecs/ECS";
import { TableEquipmentConf } from "../../common/table/TableEquipmentConf";
import { Role } from "../../role/Role";
import { Color, color } from "cc";

/** 装备数据 */
@ecs.register('EquipModel')
export class EquipModelComp extends ecs.Comp {
    /** 提供MVVM组件使用的数据 */
    vm: any = {};

    private nameColorList: Color[] = [color(146, 221, 129, 255), color(105, 228, 243, 255), color(199, 0, 208, 255), color(227, 118, 29, 255), color(187, 7, 43, 255)]
    public nameColor: Color = null!;

    private _id: number = -1;
    get id(): number {
        return this._id;
    }
    set id(value: number) {
        this._id = value;
        this.init(value);
    }

    /** 装备服务唯一编号 */
    sid: number = -1;

    /** 装备角色 */
    role: Role = null!;

    table: TableEquipmentConf = null!;

    /** 名字 */
    private _name: string = ""; 
    get name(): string {
        return this._name;
    }
    set name(value: string) {
        this._name = value;
        this.vm["name"] = this._name;
    }

    /** 颜色 */
    private _color: number = 2;
    get color(): number {
        return this._color;
    }
    set color(value: number) {
        this._color = value;
        this.vm["color"] = this._color;
        this.nameColor = this.nameColorList[value - 1];
    }

    private _atk: number = 0;
    get atk(): number {
        return this._atk;
    }
    set atk(value: number) {
        this._atk = value;
        this.vm["atk"] = this._atk;
    }

    private _def: number = 0;
    get def(): number {
        return this._def;
    }
    set def(value: number) {
        this._def = value;
        this.vm["def"] = this._def;
    }

    private _hp: number = 0;
    get hp(): number {
        return this._hp;
    }
    set hp(value: number) {
        this._hp = value;
        this.vm["hp"] = this._hp;
    }

    private _level: number = 0;
    get level(): number {
        return this._level;
    }
    set level(value: number) {
        this._level = value;
        this.vm["level"] = this._level;
    }

    private _type: number = 0;
    get type(): number {
        return this._type;
    }
    set type(value: number) {
        this._type = value;
        this.vm["type"] = this._type;
    }

    private _upgradeLevel: number = 0;
    get upgradeLevel(): number {
        return this._upgradeLevel;
    }
    set upgradeLevel(value: number) {
        this._upgradeLevel = value;
        this.vm["upgradeLevel"] = this._upgradeLevel;
    }

    private _spend: number = 0;
    get spend(): number {
        return this._spend;
    }
    set spend(value: number) {
        this._spend = value;
        this.vm["spend"] = this._spend;
    }

    private _isJinjie: number = 0;
    get isJinjie(): number {
        return this._isJinjie;
    }
    set isJinjie(value: number) {
        this._isJinjie = value;
        this.vm["isJinjie"] = this._isJinjie;
    }

    /** 开启属性数量 */
    private _attrOpenNum: number = 0;
    get attrOpenNum(): number {
        return this._attrOpenNum;
    }
    set attrOpenNum(value: number) {
        this._attrOpenNum = value;
        this.vm["attrOpenNum"] = this._attrOpenNum;
    }

    /** 开启的套装数量 */
    private _tzOpenNum: number = 0;
    get tzOpenNum(): number {
        return this._tzOpenNum;
    }
    set tzOpenNum(value: number) {
        this._tzOpenNum = value;
        this.vm["tzOpenNum"] = this._tzOpenNum;
    }

    /** 套装最大数量 */
    private _tzMaxNum: number = 0;
    get tzMaxNum(): number {
        return this._tzMaxNum;
    }
    set tzMaxNum(value: number) {
        this._tzMaxNum = value;
        this.vm["tzMaxNum"] = this._tzMaxNum;
    }

    /** 是否有套装属性 */
    private _hasTz: number = 0;
    get hasTz(): number {
        return this._hasTz;
    }
    set hasTz(value: number) {
        this._hasTz = value;
        this.vm["hasTz"] = this._hasTz;
    }

    init(id: number) {
        if (this.table == null) this.table = new TableEquipmentConf();
        this.table.init(id);
        this.name = this.table.name;
        this.type = this.table.type;
        this.color = this.table.color;
        this.tzOpenNum = 0;
        this.hasTz = 0;
        this.tzMaxNum = 0;
        this.attrOpenNum = 0;

        if (!WECHAT) {
            console.assert(`【策划】编号为【${id}】的装备数据不存在`);
        }
    }

    constructor() {
        super();
    }

    reset() {
        this.sid = -1;
        this.role = null!;
        this.table = null!;
        this._atk = 0;
        this._def = 0;
        this._hp = 0;
        this._level = 0;
        this._type = 0;
        this._upgradeLevel = 0;
        this._isJinjie = 0;
        this._spend = 0;
        this._tzOpenNum = 0;
        this._hasTz = 0;
        this._tzMaxNum = 0;
        this._attrOpenNum = 0;
    }
}